package com.rideplans.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratedStackPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.rideplans.client.home.Home;
import com.rideplans.client.planride.ListAll;
import com.rideplans.client.planride.WizardDetails;

public class MainView extends Composite {
	public static AbsolutePanel absolutePanel;
	public static Button btnLogin;
	public static Button btnRegistration;
	public static AbsolutePanel absolutePanelContent;
	public static String loginstatus;
	
	public MainView() {
		absolutePanel = new AbsolutePanel();
		initWidget(absolutePanel);
		absolutePanel.setSize("1200px", "900px");
		
		Image image = new Image("images/bike.png");
		absolutePanel.add(image, 30, 0);
		image.setSize("124px", "124px");
		
		DecoratedStackPanel decoratedStackPanel = new DecoratedStackPanel();
		absolutePanel.add(decoratedStackPanel, 0, 105);
		decoratedStackPanel.setSize("200px", "786px");
		
		AbsolutePanel absolutePanel_1 = new AbsolutePanel();
		decoratedStackPanel.add(absolutePanel_1, "Home", false);
		absolutePanel_1.setSize("100%", "100%");
		
		AbsolutePanel absolutePanel_2 = new AbsolutePanel();
		decoratedStackPanel.add(absolutePanel_2, "Plan Ride", false);
		absolutePanel_2.setSize("100%", "100%");
		
		Label lblPlanARide = new Label("Plan A Ride");
		absolutePanel_2.add(lblPlanARide, 10, 10);
		
		lblPlanARide.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				//loginstatus="back";
				absolutePanelContent.clear();
				absolutePanelContent.add(new WizardDetails());
			}
		});
		
		
		Label lblViewPlans = new Label("View Plans");
		lblViewPlans.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				//loginstatus="back";
				absolutePanelContent.clear();
				absolutePanelContent.add(new ListAll());
			}
		});
		
		absolutePanel_2.add(lblViewPlans, 10, 32);
		if(loginstatus==null)
		{
			btnLogin = new Button("Login");
			absolutePanel.add(btnLogin, 1143, 10);

			btnRegistration = new Button("Registration");
			absolutePanel.add(btnRegistration, 1052, 10);
			
			btnRegistration.addClickHandler(new ClickHandler() {
				public void onClick(ClickEvent event) {
					final Registration reg = new Registration();
					reg.show();
					reg.center();
					reg.btnRegister.addClickHandler(new ClickHandler() {
						public void onClick(ClickEvent event) {
							reg.hide();
						}
					});
				}
				});
			
			
			btnLogin.addClickHandler(new ClickHandler() {
				public void onClick(ClickEvent event) {
					loginstatus="back";
					//absolutePanel.clear();
					final Login window = new Login();
					window.show();
					window.center();
					window.btnNewButton.addClickHandler(new ClickHandler() {
						public void onClick(ClickEvent event) {
							window.hide();
							btnLogin.setText("Logout");
							btnRegistration.setVisible(false);
						}
					});
				}
			});
		}
		
		absolutePanelContent = new AbsolutePanel();
		absolutePanelContent.setStyleName("gwt-border");
		absolutePanel.add(absolutePanelContent, 206, 105);
		absolutePanelContent.setSize("984px", "785px");
		absolutePanelContent.add(new Home());
		Label lblRideplans = new Label("Rideplans");
		lblRideplans.setStyleName("gwt-Label-header-Main");
		absolutePanel.add(lblRideplans, 635, 49);
	}
}
